package com.mzpai.web.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MvcConfiguration implements WebMvcConfigurer{
	
    protected Logger logger = LoggerFactory.getLogger(MvcConfiguration.class);

    
    /**
	 * 跨域配置
	 */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")    //添加映射路径，“/**”表示对所有的路径实行全局跨域访问权限的设置
				.allowedOrigins("*")  //开放哪些ip、端口、域名的访问权限
				.allowCredentials(true)  //是否允许发送Cookie信息 
				.allowedHeaders("*")  //允许HTTP请求中的携带哪些Header信息
				.allowedMethods("*"); //开放哪些Http方法，允许跨域访问

	}
	
	 /**
     * 注册 拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LogInterceptor());
    }

}
